package com.eqs.enterprisequestionnaire.controller;

import com.eqs.enterprisequestionnaire.model.pojo.Question;
import com.eqs.enterprisequestionnaire.result.R;
import com.eqs.enterprisequestionnaire.service.ValidityAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;


@RestController
@RequestMapping("/validityAnalysis")
public class ValidityAnalysisController {

    @Autowired
    private ValidityAnalysisService validityAnalysisService;

    @PostMapping("/factorLoadings")
    public R<Map<Integer, double[]>> getFactorLoadings(@RequestBody List<Integer> questionIds) {
        Map<Integer, double[]> factorLoadings = validityAnalysisService.getFactorLoadings(questionIds);
        return R.success(factorLoadings);
    }

    @PostMapping("/kmo")
    public R<Double> calculateKMO(@RequestBody List<Integer> questionIds) {
        double kmo = validityAnalysisService.calculateKMO(questionIds);
        return R.success(kmo);
    }

    @PostMapping("/pValue")
    public R<Double> calculatePValue(@RequestBody List<Integer> questionIds) {
        double pValue = validityAnalysisService.calculatePValue(questionIds);
        return R.success(pValue);
    }
}
